FROM python:3.7

# 定义编码
ENV LC_ALL="C.UTF-8" LANG="C.UTF-8"

# 定义工作目录
WORKDIR /opt/app/

# Adding the NodeSource APT repository for Debian-based distributions repository AND the PGP key for verifying packages
RUN curl -sL https://deb.nodesource.com/setup_12.x | bash -

# Replace with Aliyun source list for apt
RUN sed -i s/archive.ubuntu.com/mirrors.aliyun.com/g /etc/apt/sources.list && \
    sed -i s/security.ubuntu.com/mirrors.aliyun.com/g /etc/apt/sources.list && \
    apt-get update && apt-get install -y nodejs tzdata && apt-get clean && \
    rm -rf /var/lib/apt/lists/*

# Update timzone of container
RUN echo "Asia/Shanghai" > /etc/timezone && rm -f /etc/localtime && \
    dpkg-reconfigure -f noninteractive tzdata

# Copy frontend folder into container
COPY frontend /opt/app/frontend

# Install frontend dependencies
RUN npm install -gd express --registry=http://registry.npm.taobao.org /opt/app/frontend/ && \
    cp /opt/app/frontend/3rd-party/*  /opt/app/frontend/node_modules/react-scripts/config/

RUN npm --prefix /opt/app/frontend/ rebuild node-sass && \
    npm --prefix /opt/app/frontend/ run build

# Replace with Tsinghua source list for pip
RUN pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple && \
    pip install --upgrade pip

RUN pip --no-cache-dir install \
        pipenv \
        flask-restful

# Install backend dependencies
COPY Pipfile* /opt/app/
RUN pipenv install --deploy --system

# Copy other files into container
COPY *.ini /opt/app/
COPY *.py /opt/app/
COPY backend /opt/app/backend

ENV PYTHONPATH=/opt/app/:${PYTHONPATH}

# 暴露端口
EXPOSE 8002

# 定义启动指令
#CMD ["twistd", "-n", "web", "--port", "tcp:port=8002", "--wsgi", "manage.app"]
CMD ["python", "manage.py"]
